home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / docs / misc / amigapl.9903.lzh / amigapl.9903 / pci.lzx / Examples / pcinet / cnet.i < prev    next >
Encoding:
Text File  |  1998-04-07  |  10.9 KB  |  252 lines

  1. ;----------------------------------------------------------------------------
  2. ;             Includes for CNET CN40-BC PCMCIA network card
  3. ;----------------------------------------------------------------------------
  4. ;           Original code by Bruce Abbott (bhabbott@inhb.co.nz)
  5. ;
  6. ;    "Some PC oriented eight (8) bit cards may require you read
  7. ;     odd-byte I/O address registers at the corresponding even-byte
  8. ;     address plus 64K.  There is sufficient I/O address space
  9. ;     provided that exceeding I/O address space should not be a problem."
  10. ;
  11. ;            (extract from Autodoc 'cardresource.doc')
  12. ;
  13. ; The following information applies to the CNet CN40BC. Other cards could
  14. ; be quite different.
  15. ;
  16. ; Even byte addresses start at $a20000, and are mirrored every 1K.
  17. ; Odd byte addresses start at $a30000. By positioning the base I/O address
  18. ; 1K below the start of odd addressing, we can access both even and odd
  19. ; I/O space using a single CPU Address Register (with 16 bit offsets).
  20. ;
  21.  
  22. ;IObase      EQU $10000-$0400+$0300      ; offset to even nic registers
  23. ;odd         EQU $10000-IOBase+$0300-1   ; offset to odd nic registers
  24.  
  25.  
  26. ;-----------------------------------------------------------------------
  27. ; The CNET CN40-BC uses a controller chip that is compatible with
  28. ; National Semiconducter's DS8390. This is the same chip that is
  29. ; used in NE1000 and NE2000 ISA bus ethernet cards.
  30.  
  31. ; --------------------- DS8390 registers ------------------------
  32. ; registers in bank 0
  33. nic_cr       EQU  0         ; command register        (r/w) in all banks
  34. nic_pstart   EQU  1         ; page start               (w)
  35. nic_pstop    EQU  2         ; page stop                (w)
  36. nic_clda0    EQU  nic_pstop ; current local dma addr   (r)
  37. nic_bnry     EQU  3         ; boundary pointer        (r/w)
  38. nic_clda1    EQU  nic_bnry  ; current local dma addr   (r)
  39. nic_tpsr     EQU  4         ; transmit page start      (w)
  40. nic_tsr      EQU  nic_tpsr  ; transmit status register (r)
  41. nic_tbcr0    EQU  5         ; transmit byte count      (w)
  42. nic_ncr      EQU  nic_tbcr0 ; number of collisions     (r)
  43. nic_tbcr1    EQU  6         ; transmit byte count      (w)
  44. nic_fifo     EQU  nic_tbcr1 ; fifo contents            (r)
  45. nic_isr      EQU  7         ; interrupt status        (r/w)
  46. nic_rsar0    EQU  8         ; remote start address     (w)
  47. nic_crda0    EQU  nic_rsar0 ; current remote DMA addr  (r)
  48. nic_rsar1    EQU  9         ; remote start address     (w)
  49. nic_crda1    EQU  nic_rsar1 ; current remote DMA addr  (r)
  50. nic_rbcr0    EQU 10         ; remote byte count        (w)
  51. nic_rbcr1    EQU 11         ; remote byte count        (w)
  52. nic_rcr      EQU 12         ; receive configuration    (w)
  53. nic_rsr      EQU nic_rcr    ; receive status           (r)
  54. nic_tcr      EQU 13         ; transmit configuration   (w)
  55. nic_cntr0    EQU nic_tcr    ; tally counter            (r) frame align errors
  56. nic_dcr      EQU 14         ; data configuration       (w)
  57. nic_cntr1    EQU nic_dcr    ; tally counter            (r) crc errors
  58. nic_imr      EQU 15         ; interrupt mask           (w)
  59. nic_cntr2    EQU nic_imr    ; tally counter            (r) missed packets
  60.  
  61. ; bank 1 and 2 registers
  62. nic_par0     EQU  1      ; physical etheraddress   (r/w)
  63. nic_par1     EQU  2      ; physical etheraddress   (r/w)
  64. nic_par2     EQU  3      ; physical etheraddress   (r/w)
  65. nic_par3     EQU  4      ; physical etheraddress   (r/w)
  66. nic_par4     EQU  5      ; physical etheraddress   (r/w)
  67. nic_par5     EQU  6      ; physical etheraddress   (r/w)
  68. nic_curr     EQU  7      ; current page            (r/w)
  69. nic_mar0     EQU  8      ; multicast etheraddress  (r/w)
  70. nic_mar1     EQU  9      ; multicast etheraddress  (r/w)
  71. nic_mar2     EQU 10      ; multicast etheraddress  (r/w)
  72. nic_mar3     EQU 11      ; multicast etheraddress  (r/w)
  73. nic_mar4     EQU 12      ; multicast etheraddress  (r/w)
  74. nic_mar5     EQU 13      ; multicast etheraddress  (r/w)
  75. nic_mar6     EQU 14      ; multicast etheraddress  (r/w)
  76. nic_mar7     EQU 15      ; multicast etheraddress  (r/w)
  77.  
  78. ; ASIC registers in the NE2000 card
  79. nic_data     EQU 16      ;  DMA port  (r/w)  16 bit
  80. nic_rst      EQU 31      ;  card reset (r=reset, w=not)
  81.  
  82. ; DS8390 command bits
  83. DSCM_STOP    EQU $01 ; Stop controller
  84. DSCM_START   EQU $02 ; Start controller
  85. DSCM_TRANS   EQU $04 ; Transmit packet
  86. DSCM_RREAD   EQU $08 ; Remote read (read from nic memory to Amiga memory)
  87. DSCM_RWRITE  EQU $10 ; Remote write (write from Amiga memory to nic memory)
  88. DSCM_NODMA   EQU $20 ; No Remote DMA present
  89. DSCM_PG0     EQU $00 ; Select register bank 0
  90. DSCM_PG1     EQU $40 ; Select register bank 1
  91. DSCM_PG2     EQU $80 ; Select register bank 2
  92.  
  93. ; tansmit status register values
  94. DSTS_PTX     EQU $01 ; Successful packet transmit
  95. DSTS_COLL    EQU $02 ; Packet transmit w/ collision
  96. DSTS_COLL16  EQU $04 ; Packet had >16 collisions & fail
  97. DSTS_UND     EQU $20 ; FIFO Underrun on transmission
  98.  
  99. ; interrupt status register values
  100. DSIS_RX      EQU $01 ; Successful packet reception
  101. DSIS_TX      EQU $02 ; Successful packet transmission
  102. DSIS_RXE     EQU $04 ; Packet reception  w/error
  103. DSIS_TXE     EQU $08 ; Packet transmission  w/error
  104. DSIS_ROVRN   EQU $10 ; Receiver overrun in the ring
  105. DSIS_CTRS    EQU $20 ; Diagnostic counters need attn
  106. DSIS_RDC     EQU $40 ; Remote DMA Complete
  107. DSIS_RESET   EQU $80 ; Reset Complete
  108.  
  109. ; interrupt mask register values
  110. DSIM_PRXE    EQU $01 ; Packet received enable
  111. DSIM_PTXE    EQU $02 ; Packet transmitted enable
  112. DSIM_RXEE    EQU $04 ; Receive error enable
  113. DSIM_TXEE    EQU $08 ; Transmit error enable
  114. DSIM_OVWE    EQU $10 ; Overwrite warning enable
  115. DSIM_CNTE    EQU $20 ; Counter overflow enable
  116. DSIM_RDCE    EQU $40 ; Remote DMA complete enable
  117. DSIM_RESET   EQU $80 ; Reset Complete enable
  118.  
  119. ; Bit numbers for interrupts (same for int status and mask)
  120. DSIB_RX      EQU 0
  121. DSIB_TX      EQU 1
  122. DSIB_RXE     EQU 2
  123. DSIB_TXE     EQU 3
  124. DSIB_ROVRN   EQU 4
  125. DSIB_CTRS    EQU 5
  126. DSIB_RDC     EQU 6
  127. DSIB_RESET   EQU 7
  128.  
  129. INTMASK EQU $ff&~(DSIM_RESET|DSIM_RDCE) ; all ints except DMA, Reset complete
  130.  
  131.  
  132. ; data configuration register values
  133. DSDC_WTS     EQU $01 ; Word Transfer Select
  134. DSDC_BOS     EQU $02 ; Byte Order Select
  135. DSDC_LAS     EQU $04 ; Long Address Select
  136. DSDC_BMS     EQU $08 ; Burst Mode Select
  137. DSDC_AR      EQU $10 ; Autoinitialize Remote
  138. DSDC_FT0     EQU $20 ; Fifo Threshold Select
  139. DSDC_FT1     EQU $40 ; Fifo Threshold Select
  140.  
  141. ; receive status register values
  142. DSRS_RPC     EQU $01 ; Received Packet Complete
  143.  
  144. ; transmit configuration register values
  145. DSTC_CRC     EQU $01 ; Inhibit CRC
  146. DSTC_LB0     EQU $02 ; Encoded Loopback Control
  147. DSTC_LB1     EQU $04 ; Encoded Loopback Control
  148. DSTC_ATD     EQU $08 ; Auto Transmit Disable
  149. DSTC_OFST    EQU $10 ; Collision Offset Enable
  150.  
  151. ; receive configuration register values
  152. DSRC_SEP     EQU $01 ; Save error packets
  153. DSRC_AR      EQU $02 ; Accept Runt packets
  154. DSRC_AB      EQU $04 ; Accept Broadcast packets
  155. DSRC_AM      EQU $08 ; Accept Multicast packets
  156. DSRC_PRO     EQU $10 ; Promiscuous physical
  157. DSRC_MON     EQU $20 ; Monitor mode
  158.  
  159.  
  160. ;-------------------------------------------------------------------------
  161. ; Packet receive header, 1 per each buffer page used in receive packet.
  162. ; The nic inserts this in front of the received packet.
  163. ;
  164.  STRUCTURE prhdr,0
  165.    BYTE  prhdr_status  ; is this a good packet, same as ds0_rsr
  166.    BYTE  prhdr_nxtpg   ; next page of packet or next packet
  167.    BYTE  prhdr_sz0     ; length (lower byte)
  168.    BYTE  prhdr_sz1     ; length (upper byte)
  169.   LABEL  prhdr_sizeof
  170.  
  171. ;-------------------------------------------------------------------------
  172. ; nic has 16K of on-board RAM, from $4000 to $7fff (16 bit address)
  173. ;
  174. ; Internal DMA operations (ie. tx/rx) require the upper 8 bits of the
  175. ; address, as RAM is addressed in 256 byte pages.
  176. ;
  177. ; DMA to/from the host Amiga ("Remote DMA") requires a 16 bit word-aligned
  178. ; address
  179. ;
  180.  
  181. PKTSZ    EQU  $0600             ; space for biggest ethernet packet (6 pages)
  182.  
  183. TBUF     EQU  $4000             ; Starting location of Transmit Buffer
  184. TBUF1    EQU  $4000+PKTSZ       ; Another Tx Buffer (for double-buffered tx)
  185. RBUF     EQU  $4000+(PKTSZ*2)   ; Starting location of Receive Ring Buffer
  186. RBUFEND  EQU  $8000             ; Ending location of Receive Ring Buffer
  187.  
  188. ETHER_MIN_LEN EQU 64            ; smallest acceptable packet size
  189. ETHER_MAX_LEN EQU 1536          ; largest raw packet size
  190.  
  191. ; ethernet packet data sizes (maximum)
  192.  
  193. ETHERPKT_SIZE EQU 1500
  194. RAWPKT_SIZE   EQU 1514
  195.  
  196. ; size of our packet buffer
  197.  
  198. PKTBUF_SIZE   EQU 1600   ; actually only need 1536 ?
  199.  
  200. ; ethernet address bytesize
  201.  
  202. ETHER_ADDR_SIZE EQU 6
  203.  
  204. ; structure of an ethernet packet
  205.  
  206.   STRUCTURE etherpacket,0
  207.    STRUCT ether_dest,ETHER_ADDR_SIZE     ;  0 destination address
  208.    STRUCT ether_src,ETHER_ADDR_SIZE      ;  6 originator  address
  209.     WORD  ether_type                     ; 12 packet type
  210.    LABEL  ether_data                     ; 14 user data (up to 1500 bytes)
  211.  
  212.  
  213. ; our extension to device data
  214.  
  215.   STRUCTURE device_data,LIB_SIZE
  216.     BYTE  dd_flags                             ; various flags
  217.     BYTE  dd_dcr                               ; copy of nic data config reg
  218.     BYTE  dd_rcr                               ; copy of nic rx config reg
  219.     BYTE  dd_imr                               ; copy of nic intmask register
  220.     LONG  dd_overflows                         ; nic rx buffer overflow count
  221.     LONG  dd_errors                            ; bad packets received
  222.     LONG  dd_collisions                        ; tx collision count
  223.     LONG  dd_seglist                           ; device seglist
  224.     APTR  dd_copytobuf                         ; caller's read routine
  225.     APTR  dd_copyfrombuf                       ; caller's write routine
  226.     APTR  dd_pcires                            ; micronik_pci.resource base
  227.     APTR  dd_pcielib                           ; pciexpansion.library base
  228.     APTR  dd_mapping_main                      ; Mapping struct for main thread
  229.     APTR  dd_mapping_rx                        ; Mapping struct for rx int
  230.     APTR  dd_mapping_tx                        ; Mapping struct for tx int
  231.     APTR  dd_mapping_int                       ; Mapping struct for status int
  232.     APTR  dd_pciconfig                         ; card's PCI definition
  233.                                                ; from pciexpansion.library
  234.    STRUCT dd_romstationaddress,ETHER_ADDR_SIZE ; hardware address from ROM
  235.    STRUCT dd_stationaddress,ETHER_ADDR_SIZE    ; hardware station addr used
  236.    STRUCT dd_readlist,MLH_SIZE                 ; read requests
  237.    STRUCT dd_writelist,MLH_SIZE                ; write requests
  238.    STRUCT dd_eventlist,MLH_SIZE                ; events
  239.    STRUCT dd_netinterrupt,IS_SIZE              ; interrupt
  240.    STRUCT dd_txint,IS_SIZE                     ; transmit software interrupt
  241.    STRUCT dd_rxint,IS_SIZE                     ; receive software interrupt
  242.     LABEL dd_extsize
  243.  
  244.  
  245. ; bit definitions for dd_flags
  246.  
  247.  BITDEF DD,NICUP,2          ; controller hardware is initialised
  248.  BITDEF DD,CONFIGURED,4     ; hardware address is configured
  249.  BITDEF DD,ONLINE,5         ; device is online
  250.  BITDEF DD,TX,6             ; transmit buffer is full
  251.  BITDEF DD,DEVINIT,7        ; device is initialised
  252.